home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / TRAPZD.DEM < prev    next >
Text File  |  1991-04-29  |  782b  |  38 lines

  1. PROGRAM d4r1(input,output);
  2. (* driver for routine trapzd *)
  3. CONST
  4.    nmax=14;
  5.    pio2=1.5707963;
  6. VAR
  7.    glit : integer;
  8.    i : integer;
  9.    a,b,s : real;
  10.  
  11. FUNCTION func(x : real) : real;
  12. (* Test function *)
  13. BEGIN
  14.    func := sqr(x)*(sqr(x)-2.0)*sin(x)
  15. END;
  16.  
  17. FUNCTION fint(x : real) : real;
  18. (* Integral of test function *)
  19. BEGIN
  20.    fint := 4.0*x*(sqr(x)-7.0)*sin(x)-
  21.          (sqr(sqr(x))-14.0*sqr(x)+28.0)*cos(x);
  22. END;
  23.  
  24. (*$I MODFILE.PAS *)
  25. (*$I TRAPZD.PAS *)
  26.  
  27. BEGIN
  28.    a := 0.0;
  29.    b := pio2;
  30.    writeln ('integral of func with 2^(n-1) points');
  31.    writeln ('actual value of integral is',fint(b)-fint(a):12:6);
  32.    writeln ('n':6,'approx. integral':24);
  33.    FOR i := 1 to nmax DO BEGIN
  34.       trapzd(a,b,s,i);
  35.       writeln (i:6,s:20:6)
  36.    END
  37.  END.
  38.